package timeslice
{
	import flash.utils.Dictionary;
	
	import slices.TimeSlice;
	import globals.$config;
	import loaders.GroupLoader;
	import loaders.LoadItem;
	import loaders.LoadManager;
	
	public class LoadResource extends TimeSlice
	{
		private var _loader:GroupLoader;
		public var urls:Array;
		public var types:Array;
		
		public var items:Dictionary;
		
		public function LoadResource(urls:Array, types:Array)
		{
			super();
			this.urls = urls;
			this.types = types;
		}
		
		override public function onStart():void {
			_loader = new GroupLoader();
			for (var i:int = 0; i < urls.length; i++) {
				_loader.add(urls[i], types[i], urls[i]);
			}
			_loader.start(onResourceLoaded, null);
		}
		
		private function onResourceLoaded(loader:GroupLoader):void {
			items = new Dictionary;
			for each (var item:LoadItem	in _loader.items)
			{
				items[item.param] = item.loader.getContent();
			}
			addOutput(PORT_RESOURCE, items);
			isEnd = true;
		}

	}
}